<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>审核商品</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css"/>
    <!-- <link rel="stylesheet" href="css/comments.css"> -->
    <link rel="stylesheet" href="css/goods.css">
    <style>
		.maincontainer {
		    padding: 10px;
		}
        .layui-form-label{
            width: 150px;
        }
        @media screen and (max-width: 450px){
            .layui-form-item .layui-input-inline {
                margin-left: 180px;
            }
        }
        .layui-input-block{
            margin-left: 180px;
        }
        .addFile{
            width: 100px;
            height: 30px;
            border-radius: 4px;
            border: 1px dashed #e6e6e6;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: #666;
            font-size: 12px;
        }
        .addFile:hover {
            border: 1px dashed #f58843;
            background: linear-gradient(316deg,#f58843 0%,#f56643 100%);;
            color: #fff;
        }
        .addFile:hover i {
            color: #fff;
        }
        .addFile i {
            font-size: 14px;
            color: #f5dab0;
            margin-right: 5px;
        }
        .fileUpLoadDiv{
            padding: 0 0 5px 0;
            display: none;
        }
        .fileUpLoadName{
            color: #03A9F4;
            cursor: pointer;
        }
        .fileUpLoadView{
            cursor: pointer;
            margin-left: 10px;
        }
        #demo1{
            width: 375px;
            height: 668px;
            border: 1px solid #f3f3f9;
            overflow-y: scroll;
            border-radius: 5px;
            background: #fff;
            padding: 10px;
        }
        #demo1 img{
            width: 100%;

        }
        .layui-form-checked>span{
            color: #fbaf7e!important;
        }
    </style>
</head>
<style>
</style>
<body>
<div class="maincontainer">
    <blockquote class="layui-elem-quote">
        审核商品
        <button type="button" class="layui-btn layui-btn-sm" style="float: right;margin-top: -4px;" onclick="onback()">返回</button>
    </blockquote>
    <div class="all-info">
		<form class="layui-form checkForm" action="">
			<div class="layui-form-item">
			  <div class="layui-form-label"><input type="checkbox" name="name" title="商品名称：" lay-skin="primary"></div>
			  <div class="layui-form-mid layui-word-aux name"></div>
			</div>
			<div class="layui-form-item">
			  <div class="layui-form-label"><input type="checkbox" name="brand" title="品牌：" lay-skin="primary"></div>
			  <div class="layui-form-mid layui-word-aux brand"></div>
			</div>
			<div class="layui-form-item layui-inline">
				<div class="layui-form-label"><input type="checkbox" name="categoryId" title="所属分类：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux categoryId"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="unit" title="计量单位：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux unit"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="sortNumber" title="排序值：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux sortNumber"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="searchKeyWord" title="搜索关键字：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux searchKeyWord"></div>
            </div>
            <!-- <div class="layui-form-item">
			 	<div class="layui-form-label"><input type="checkbox" name="updateStatus" title="是否可改单：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux updateStatus"></div>
            </div> -->
            <div class="layui-form-item">
			 	<div class="layui-form-label"><input type="checkbox" name="publicStatus" title="是否公示：" lay-skin="primary"></div>
                <!-- <div class="layui-form-mid layui-word-aux publicStatus"></div> -->
                <div class="layui-input-block">
                    <input type="radio" name="publicStatusr" value="1" title="是">
                    <input type="radio" name="publicStatusr" value="0" title="否" checked="">
			 	</div>
				<div class="layui-form-mid layui-word-aux">（是否公示由平台决定）</div>
			 </div>
			 <div class="layui-form-item">
			 	<div class="layui-form-label"><input type="checkbox" name="quoteStatus" title="是否快速报价商品：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux quoteStatus" ></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="productSpecVoList" title="商品规格属性：" lay-skin="primary"></div>
                <div class="layui-input-block mytable">
                    
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="reportDueTime" title="检测报告到期时间：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux reportDueTime"></div>
            </div>
            <div class="layui-form-item">
			 	<div class="layui-form-label"><input type="checkbox" name="mainImage" title="商品主图：" lay-skin="primary"></div>
			 	<div class="layui-input-inline">
			 		<div class="imgList">
			 			<ul class="mainpicture">
			 				<li class="nullimg mainImg">
			 					<div> 
			 						<i class="layui-icon layui-icon-upload"></i>
			 						<p>上传商品主图</p>
			 					</div>
			 				</li>
			 				<li class="showMImg" style="display: none">

			 				</li>
			 			</ul>
			 			<div class="layui-form-mid layui-word-aux">建议上传图片尺寸:334*320,不超过500K</div>
			 		</div>
			 	</div>
            </div>
            <div class="layui-form-item">
			 	<div class="layui-form-label"><input type="checkbox" name="smallPic" title="商品图片：" lay-skin="primary"></div>
			 	<div class="layui-input-inline">
			 		<div class="imgList">
			 			<ul class="mainpicture">
			 				<li class="nullimg detailsImg">
			 					<div> 
			 						<i class="layui-icon layui-icon-upload"></i>
			 						<p>上传商品图片</p>
			 					</div>
			 				</li>
			 				<li class="showDImg1" style="display: none">

			 				</li>
			 			</ul>
			 			<div class="layui-form-mid layui-word-aux">建议上传图片尺寸:750*680,不超过3M,最多可上传20张轮播图</div>
			 		</div>
			 	</div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="layui-form-label"><input type="checkbox" name="content" title="商品描述：" lay-skin="primary"></div>
                <div class="layui-input-block">
                    <div id="demo1"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"><input type="checkbox" name="annexFiles" title="商品附件：" lay-skin="primary"></div>
                <div class="layui-form-mid layui-word-aux">注（请上传营业执照、生产许可证、检测报告）</div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-label"></div>
                <div class="layui-input-block">
                    <div class="fileUpLoadDiv">
                        
                    </div>
                </div>
            </div>
		</form>
		
	</div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script src="js/productLabelFormat.js"></script>
<script src="js/product.js"></script>
<script>
	layui.config({
	    base: 'plugins/layui/modules/'
	}).use(['layer', 'form', 'http','table'], function () {
	    var layer = layui.layer,
	        http = layui.http,
			form = layui.form;
			
			window.onback = function() {
				window.history.back();
				// $(window.parent.document).find('.maincontainer').show()
				// $(window.parent.document).find('#my_iframe').hide()
				// window.parent.layui.table.reload('selectTable')
			}
			
			// ------------------------ 回显信息 ------------------------
			
            var id = http.getPid('id');
            
            $('.checkForm').append('<div class="layui-form-item"><div class="layui-form-label">审核备注：</div><div class="layui-input-block"><textarea name="reviewResult" placeholder="请输入审核备注" class="layui-textarea"></textarea></div></div><div class="layui-form-item"><div class="layui-input-block"><button type="button" class="layui-btn checkAgree">审核通过</button><button type="button" class="layui-btn layui-btn-primary checkDeny" lay-submit="" lay-filter="demo1">审核不通过</button></div></div>')
            
			
			var specificationList = [];
			var specificationList1 = '';
			var speciGoodList = [];
            var annexFiles = [] // 附件
			
            getInfo()
			function getInfo(){
				http.get('admin/product/findById',{productId:id},function(res){
					var data = res.data;
					
					// 列表查询所有食堂等级
					http.get('admin/supplier/label/listAll',{
						supplierId: data.shops
					},function(res){
						if(res.code == 200){
							canteenLabelList = res.data
							
							getTable(data.goodVoList);//回显规格值
						}else{
							layer.msg(res.msg)
						}
					})

					$('.name').html(data.name);
					$('.brand').html(data.brandName)
					$('.unit').html(data.unitName)
					$('.sortNumber').html(data.sortNumber)
					$('.searchKeyWord').html(data.searchKeyWord)
					// $('.updateStatus').html(data.updateStatus == 1?'是':'否')
					// $('.publicStatus').html(data.publicStatus == 1?'是':'否')	
					if(data.publicStatus == 0)
						$('input[name=publicStatusr]').eq(1).attr('checked',true)
					if(data.publicStatus == 1)
						$('input[name=publicStatusr]').eq(0).attr('checked',true)
						
					$('.quoteStatus').html(data.quoteStatus == 1?'是':'否')
					$('.reportDueTime').html(data.reportDueTime?data.reportDueTime.split(' ')[0]:'');
                    $('.reviewResult').html(data.reviewResult)
                    $('.shelfDownReason').html(data.shelfDownReason)
					
					// 分类
					categoryFunction(data.categoryId)
					// 商品主图
					if(data.mainImage){
						$('.mainImg').hide()
						$('.showMImg').show().siblings('li').hide();
						var imgId = http.getUUID();
						var html = '<div id="div'+imgId+'" class="imgdiv" onmouseover="showOperation(\'span'+imgId+'\')" onmouseout="hideOperation(\'span'+imgId+'\')">'+
                                        '<img onurl="'+data.mainImage+'" src="'+(TUrl+data.mainImage)+'" id="proimg'+imgId+'">'+
                                    '</div>';
						
						$('.showMImg').html(html);
					}
					//商品图片
					if(data.smallPic){
						$('.detailsImg').hide()
						$('.showDImg1').show().siblings('li').hide();
						var imghtml = '';
						var smallPic = JSON.parse(data.smallPic);
						for(var i=0;i<smallPic.length;i++){
							var imgId = http.getUUID();
							imghtml += '<div id="div'+imgId+'" class="imgdiv" onmouseover="showOperation(\'span'+imgId+'\')" onmouseout="hideOperation(\'span'+imgId+'\')">'+
											'<img onurl="'+smallPic[i]+'" src="'+(TUrl+smallPic[i])+'" id="proimg'+imgId+'">'+
										'</div>';
						}
						$('.showDImg1').html(imghtml);
					}
							
                    document.getElementById('demo1').innerHTML = data.content

					// 附件
					if(data.annexFiles){
						$('.fileUpLoadDiv').show()
						var annexFiles1 = JSON.parse(data.annexFiles)
						annexFiles = annexFiles1
						var html = ''
						for(var j=0;j<annexFiles1.length;j++){
                            html += '<div><span class="fileUpLoadName">'+annexFiles1[j].filename+'</span><span class="fileUpLoadView" data-file="'+annexFiles1[j].file+'">预览</span></div>'
						}
						$('.fileUpLoadDiv').append(html)
					}
							
					form.render();
					 
					 //规格
					specificationList = [];
					var s = data.productSpecVoList;
					for(var j=0;j<s.length;j++){
						var p = {
							name: s[j].specName
						}
						var p_enums = [];
						for(var k=0;k<s[j].productSpecValueList.length;k++){
							p_enums.push(s[j].productSpecValueList[k].specValue)
						}
						p.p_enums = p_enums;
						specificationList.push(p)
					}
					specificationList1 = testProduct(specificationList);//调用product.js中方法
				})
			}
			
			
			function getTable(goodVoList){//回显规格明细
				if(goodVoList.length>0){
					var tableH = '<table class="layui-table inputTable"><thead><tr><th>商品编号</th>';
											
					for(var i=0;i<specificationList.length;i++){
						tableH += '<th>'+specificationList[i].name+'</th>'
					}
					tableH += '<th><div><span>默认商品价格</span></div></th>';
							           
					// 食堂等级(2020/12/5新增)
					for(var g=0;g<canteenLabelList.length;g++){
						tableH += '<th><div><span>'+canteenLabelList[g].labelName+'单价</span></div></th>'
					}
					tableH += '</tr></thead><tbody>'
					
					for(var j=0;j<goodVoList.length;j++){
						tableH += '<tr><td class="my_goodNo">'+goodVoList[j].goodNo+'</td>'
						for(var k=0;k<goodVoList[j].goodSpecVoList.length;k++){
							tableH += '<td>'+goodVoList[j].goodSpecVoList[k].specValue+'</td>';
						}
						tableH += '<td>'+goodVoList[j].price+'</td>'
						
						// 食堂等级
						var list = labelInfoWith(canteenLabelList, goodVoList[j].goodLabelPriceList) // 食堂等级列表对应价格(2020/12/8新增)
						for (var g=0;g<list.length;g++) {
							tableH += '<td>'+(list[g].goodPrice?list[g].goodPrice:goodVoList[j].price)+'</td>'
						}
					}     
			
					tableH += '</tbody></table>';
			
					$('.mytable').html(tableH)
				}
			}
			
			// -------------- 分类 start --------------------
			function categoryFunction(categoryId){
				http.get('admin/product/category/listAllByCategoryId',{
					categoryId: categoryId
				},function(res){
					if(res.code == 200){
						// $('.categoryId').html(res.data.categoryName+'>'+res.data.childCategory[0].categoryName);
						var html = res.data.categoryName;
						if(res.data.childCategory && res.data.childCategory.length>0){
							html += '>'+res.data.childCategory[0].categoryName;
						}
						$('.categoryId').html(html);
					}else{
						layer.msg(res.msg)
					}
				})
			}
			// -------------- 分类 end --------------------

			// ------------------- 商品附件 start ----------------------
			// 预览
			$(document).on('click','.fileUpLoadView',function(e){
				var file = e.target.dataset.file
				window.open(TUrl+file)
			})
			// ------------------- 商品附件 end ----------------------
			
			
			$(document).on('click','.checkAgree',function(){ // 通过审核
                var reviewResult = $('textarea[name=reviewResult]').val()
                // if(!reviewResult){
                //     layer.msg('请输入审核备注')
                //     return
                // }
                myCheck(1,reviewResult)
            })
            form.on('submit(demo1)', function(data){ // 审核不通过
                var reviewResult = $('textarea[name=reviewResult]').val()
                var reviewFailureField = ''
                if(!reviewResult){
                    layer.msg('请输入审核备注')
                    return
                }
                var list = $('input[type=checkbox]:checked')
                Object.keys(data.field).forEach(key=>{
                    if(key!='reviewResult'&&data.field[key])
                        reviewFailureField += key + ','
                })
                
                // console.log(reviewFailureField)
                if(!reviewFailureField){
                    layer.msg('请选择不通过的字段')
                    return
                }
                myCheck(2,reviewResult,reviewFailureField)
            })
            function myCheck(reviewStatus,reviewResult,reviewFailureField){
				var publicStatus = $('input[name=publicStatusr]:checked').val();//是否公示
                http.post('admin/product/review',{
                    productId: id,
                    reviewStatus: reviewStatus,
                    reviewResult: reviewResult,
                    publicStatus: publicStatus,
                    reviewFailureField: reviewFailureField
                },function(res){
                    if(res.code == 200){
                        layer.msg('操作成功')
                        setTimeout(function(){
                            // window.history.back()
							onback()
                        },500)
                    }else{
                        layer.msg(res.msg)
                    }
                })
            }
    })
	
	//显示图片操作
	function showOperation(imgId){
		$('#'+imgId+'').show();
	}
	//隐藏图片操作
	function hideOperation(imgId){
		$('#'+imgId+'').hide();
	}
	//图片移除
	function deleteimg(imgId){
		$('#'+imgId+'').remove();		
	}
</script>
</body>

</html>